from rest_framework import serializers
from doctors.models import DoctorModel, LabelModel, AnswerModel, AnswerImageModel
from hospitals.models import IllnessModel


class IllnessModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = IllnessModel
        fields = ['id', 'name']


class LabelModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = LabelModel
        fields = ['id', 'name']


class DoctorModelSerializer(serializers.ModelSerializer):
    hospital_name = serializers.CharField(source='hospital.name', read_only=True)
    hospital_level = serializers.CharField(source='hospital.get_level_display', read_only=True)
    department_name = serializers.CharField(source='department.name', read_only=True)
    illness = IllnessModelSerializer(many=True)
    label = LabelModelSerializer(many=True)

    class Meta:
        model = DoctorModel
        fields = ['id', 'name', 'get_title_display', 'hospital_name', 'department_name', 'avatar', 'profile', 'hospital_level', 'get_status_display',
                  'illness', 'label', 'request_time', 'price', 'status']


class AnswerModelSerializer(serializers.ModelSerializer):
    create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", read_only=True)
    update_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", read_only=True)

    class Meta:
        model = AnswerModel
        fields = ['id', 'user_content', 'doctor_content', 'create_time', 'update_time', 'is_public']


class AnswerImageModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = AnswerImageModel
        fields = '__all__'
